package org.credo.thread;

public class Thread_join extends Thread{

	public static void main(String[] args) throws InterruptedException {
		new Thread_join("new Thread").start();
		for(int i=0;i<100;i++){
			if(i==20){
				Thread_join thread=new Thread_join("by join's Thread.");
				thread.start();
				//main线程调用了jt线程的join方法,main线程必须等jt执行完才能继续执行.
				thread.join();
			}
			System.out.println(Thread.currentThread().getName()+" "+i);
		}
	}
	
	//提供一个有参的构造函数,用于设置线程的名字
	public Thread_join(String name){
		super(name);
	}
	
	public void run(){
		for(int i=0;i<100;i++){
			System.out.println(getName()+" "+i);
		}
	}
}
